package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.common.annotation.Log;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.query.search.AlbumIndexQuery;
import com.atguigu.tingshu.search.repository.AlbumIndexRepository;
import com.atguigu.tingshu.search.service.SearchService;
import com.atguigu.tingshu.vo.search.AlbumInfoIndexVo;
import com.atguigu.tingshu.vo.search.AlbumSearchResponseVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.AbstractList;
import java.util.List;
import java.util.Map;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search/albumInfo")
@SuppressWarnings({"all"})
public class SearchApiController {

    @Autowired
    private SearchService searchService;

    @Autowired
    private AlbumIndexRepository albumIndexRepository;

    //专辑上架
    @Operation(summary = "专辑上架")
    @GetMapping("/upperAlbum/{albumId}")
    public Result upperAlbum(@PathVariable(value = "albumId") Long albumId){
        searchService.upperAlbum(albumId);
        return  Result.ok();
    }

    //专辑下架
    @Operation(summary = "专辑下架")
    @GetMapping("/lowerAlbum/{albumId}")
   public Result lowerAlbum(@PathVariable(value = "albumId") Long albumId){
        searchService.lowerAlbum(albumId);
        return Result.ok();
    }
    //专辑批量上架
    @Operation(summary = "专辑批量上架")
    @GetMapping("/batchUpperAlbum")
    public Result batchUpperAlbum() {

        for (Long i = 1L; i <=1500; i++) {
            upperAlbum(i);
        }
        return Result.ok();
    }

    //根据关键词搜索
    @Operation(summary = "根据关键词搜索")
    @PostMapping
    public Result searchBykey(@RequestBody AlbumIndexQuery albumIndexQuery){
        AlbumSearchResponseVo albumSearchResponseVo =  searchService.searchBykey(albumIndexQuery);
        return Result.ok(albumSearchResponseVo);
    }

    //获取频道页数据
    @Operation(summary = "获取频道页数据")
    @GetMapping("/channel/{category1Id}")
    public Result channel(@PathVariable(value = "category1Id") Long category1Id){
    List<Map<String,Object>> mapList =  searchService.channel(category1Id);
        return Result.ok(mapList);
    }

    //实现自动补全功能
    @Operation(summary = "自动补全")
    @GetMapping("/completeSuggest/{keyword}")
    public Result completeSuggest(@PathVariable(value = "keyword") String keyword){
     List<String> list =  searchService.completeSuggest(keyword);
        return Result.ok(list);
    }

    //更新排行榜
    @Operation(summary = "更新排行榜")
    @GetMapping("/updateLatelyAlbumRanking")
    public Result updateLatelyAlbumRanking(){
        searchService.updateLatelyAlbumRanking();
        return Result.ok();
    }

    //获取排行榜列表
    @Operation(summary = "获取排行榜列表")
    @Parameters({
            @Parameter(name = "category1Id",description = "一级分类",in = ParameterIn.PATH,required = true),
            @Parameter(name = "dimension",description = "热度:hotScore、播放量:playStatNum、订阅量:subscribeStatNum、购买量:buyStatNum、评论数:albumCommentStatNum",required = true,in = ParameterIn.PATH),
    })
    @GetMapping("findRankingList/{category1Id}/{dimension}")
    public Result<List<AlbumInfoIndexVo>> findRankingList(@PathVariable Long category1Id, @PathVariable String dimension) {
    List<AlbumInfoIndexVo> albumInfoIndexVoList =   searchService.findRankingList(category1Id,dimension);
    return Result.ok(albumInfoIndexVoList);
    }

}

